<template>
  <div>
    <el-dialog class="bg-white-dialog" :visible.sync="showDialog" width="1220px" :close-on-click-modal="false" :close-on-press-escape="false">
      <div slot="title">
        <div class="flex justify-between align-center padding-right-30">
          <div>
            <span class="color-333333 font-size-18 font-weight-700 padding-right-20">{{title}}</span>
            <span class="color-666666">单位：㎡</span>
          </div>
          <div>
            <span class="color-666666 padding-right-20">财年&nbsp;{{ fiscalYear }}</span>
            <span class="color-666666">日期&nbsp;{{ fiscalYear }}-{{ fiscalMonth }}-{{ fiscalDay }}</span>
          </div>
        </div>
      </div>
      
      <dialog-lease-table :tableData="tableData.slice(0, 1)" :selectTime="selectTime" :dialog-type="dialogType"></dialog-lease-table>
      <dialog-lease-table class="margin-top-10" :tableData="tableData.slice(1)" :selectTime="selectTime" :dialog-type="dialogType" :show-head="false"></dialog-lease-table>
    </el-dialog>
  </div>
</template>
<script>
  import { apiRentalRateDetail } from '@a/about';
  import dialogLeaseTable from "./dialogLeaseTable.vue"

  import dayjs from 'dayjs';

  export default {
    props: {
      selectTime: {
        type: Number,
        default: 0,
      },
      universalParams: {
        type: Object,
        default: () => {
          return {};
        },
      },
      dialogType: {
        type: Number,
        default: 1,
      },
    },

    computed: {
      fiscalYear() {
        return dayjs(this.selectTime).format('YYYY');
      },
      fiscalMonth() {
        let date = dayjs(this.selectTime).format('YYYY-MM-DD');
        let month = date.split('-')[1];
        return Number(month);
      },
      fiscalDay() {
        let day = new Date(new Date(this.fiscalYear, this.fiscalMonth).setDate(0)).getDate();
        return day
      },
      title() {
        return this.dialogType == 11 ? "空置业态面积占比情况" : "已租业态面积占比情况"
      },
      typeName() {
        return this.dialogType == 11 ? "空置" : "在租"
      }
    },

    data() {
      return {
        showDialog: false,
        tableData: [],
      };
    },

    methods: {
      init() {
        this.getData();
        this.showDialog = true;
      },

      async getData() {
        let params = this.lodash.cloneDeep(this.universalParams)
        params.assetState = this.dialogType == 11 ? 2 : 1
        let res = await apiRentalRateDetail(params);
        this.tableData = res.rows || [];
      },

      goInfo(row, type) {
        let pathName = '';
        let planName = '';
        let planProjectName = '';
        if (row.projectKey == "group") {
          pathName = 'groupmonth-all-plan';
          planName = '集团月报'; //集团月保
          planProjectName = "集团"
        } else {
          pathName = 'execute-all-plan';
          planName = '项目月报'; ////项目月保
          planProjectName = row.projectName
        }

        let queryData = {
          headerName: planName,
          year: this.fiscalYear || '',
          month: this.fiscalMonth,
          planProjectName:planProjectName
        };

        if (row.projectKey && row.projectKey != "group") {
          queryData.projectKey = row.projectKey
        }

        let pathUrl = {
          name: pathName,
          query: queryData,
        };

        let { href } = this.$router.resolve(pathUrl);
        window.open(href);
      },
    },

    components:{dialogLeaseTable}
  };
</script>

<style lang="scss" scoped>
  ::v-deep .el-table {
    .el-table__header-wrapper {
      .head1 {
        background: rgba(247, 145, 0, 0.25) !important;
      }
      .head2 {
        background: rgba(247, 145, 0, 0.1) !important;
      }
    }
    th .cell{
      font-size: 14px;
      padding: 0 3px;
    }
  }

  ::v-deep .has-bg{
    .el-table__body-wrapper{
        .el-table__row{
            background: rgba(51,132,254,0.2);
        }
    }
  }
</style>
